#include <iostream>

const int LIM = 8;

template <typename T>
void Swap(T &a, T &b);//original templete

template <typename T>
void Swap(T *a, T *b, int n);//new templete

void Show(int a[]);
void two_templates_test();

int main(int argc, char const *argv[])
{
    two_templates_test();
    return 0;
}

void two_templates_test()
{
    int i = 10, j = 20;
    using namespace std;
    cout << "i, j =" << i << ", " << j << ".\n";
    cout << "Using Compiler-generated in swapper:\n";
    Swap(i ,j);         //matches original template
    cout << "Now i, j =" << i << ", " << j << ".\n";

    int d1[LIM] = {0, 7, 0, 4, 1, 7, 7, 6};
    int d2[LIM] = {0, 7, 2, 0, 1, 9, 9, 6};
    cout << "Original arrays:\n";
    Show(d1);
    Show(d2);
    Swap(d1, d2, LIM);//matches new template

    cout << "Swapped arrays:\n";
    Show(d1);
    Show(d2);

    return ;
}


template <typename T>
void Swap(T &a, T &b)
{
    T temp = a;
    a = b;
    b = temp;
}

template <typename T>
void Swap(T *a, T *b, int n)
{
    T temp;
    for (int i = 0; i < n; ++i) {
        temp = a[i];
        a[i] = b[i];
        b[i] = temp;
    }
}

void Show(int a[])
{
    using namespace std;
    cout << a[0] << a[1] << "/";
    cout << a[2] << a[3] << "/";
    for (int i = 4; i < LIM; ++i) {
        cout << a[i];
    }
    cout << endl;
}

